//
//  YSCardVideoItemFrame.m
//  Yueshi
//
//  Created by yueshi－mac1 on 15/12/16.
//  Copyright © 2015年 悦食中国. All rights reserved.
//

#import "YSCardVideoItemFrame.h"

@implementation YSCardVideoItemFrame
-(void)setAdvert:(YSAdvert *)advert{
    _advert = advert;
    
    CGFloat videoHeight = (SCREENW-YSPublicXInset*2)/1.5;
    self.videoFrame = CGRectMake(YSPublicXInset, 0, SCREENW-YSPublicXInset*2, videoHeight);
    self.cellHeight = CGRectGetMaxY(self.videoFrame);
    
    if(!ISBLANK(advert.advertTitle)){
        self.videoFrame = CGRectMake(YSPublicXInset, 0, SCREENW-YSPublicXInset*2, videoHeight);
        self.cellHeight = CGRectGetMaxY(self.videoFrame);
        
        if(ISBLANK(advert.advertIcon)){//判断如果为空就隐藏icon
            //描述图标
            self.iconImageFrame = CGRectMake(YSPublicXInset,CGRectGetMaxY(self.videoFrame)+YSPublicXInset, 0, 21);
            //描述
            CGFloat descX = CGRectGetMaxX(self.iconImageFrame);
            CGFloat descY = CGRectGetMinY(self.iconImageFrame);
            CGSize descSize = [advert.advertTitle sizeWithFont:SYS_FONT(DescFont)];
            self.descFrame  = (CGRect){{descX, descY}, descSize};
        }else{
            //描述图标
            self.iconImageFrame =  CGRectMake(YSPublicXInset, CGRectGetMaxY(self.videoFrame)+YSPublicXInset, 21, 21);
            //描述
            CGFloat descX = CGRectGetMaxX(self.iconImageFrame) + 4;
            CGFloat descY = CGRectGetMinY(self.iconImageFrame);
            CGSize descSize = [advert.advertTitle sizeWithFont:SYS_FONT(DescFont)];
            self.descFrame  = (CGRect){{descX, descY}, descSize};
        }
        
        //子描述
        CGFloat subDescX = YSPublicXInset;
        CGFloat subDescY = CGRectGetMaxY(self.iconImageFrame) + 5;
        CGSize subDescSize = [advert.advertText sizeWithFont:SYS_FONT(SubDescFont)constrainedToSize:CGSizeMake(SCREENW-YSPublicXInset*2, SubDescFont)];
        self.subDescFrame = (CGRect){{subDescX, subDescY}, subDescSize};
        self.cellHeight = CGRectGetMaxY(self.subDescFrame)+YSPublicXInset*2;
        
    }else if(!ISBLANK(advert.advertText)){
        //子描述
        CGFloat subDescX = YSPublicXInset;
        CGFloat subDescY = CGRectGetMaxY(self.videoFrame) + YSPublicXInset;
        CGSize subDescSize = [advert.advertText sizeWithFont:SYS_FONT(SubDescFont) constrainedToSize:CGSizeMake(SCREENW-YSPublicXInset*2, SubDescFont)];
        self.subDescFrame = (CGRect){{subDescX, subDescY}, subDescSize};
        
        self.cellHeight = CGRectGetMaxY(self.subDescFrame)+YSPublicXInset*2;
    }
    
    //自己的frame
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = SCREENW;
    CGFloat h = self.cellHeight;
    self.frame = CGRectMake(x, y, w, h);
}

@end
